﻿#region
/*******************************************************************************
** File Name:		    TableAreaService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using EWineShop.Service.Contracts;
using EWineShop.Service.Model;
using EWineShop.IBatisRepository;
using EWineShop.Respository;
using System.Data;
using EWineShop.Entity;

namespace EWineShop.Service
{
    public class TableAreaService : ITableAreaService
    {
		 ITableArea tableArea = new TableAreaRepository();
		 
		 #region  Auto Generation
		 

		public void UpdateByTableAreaID (TableAreaModel model)
		{
			ETableArea entity = ConvertModelToEntity(model);

            tableArea.UpdateByTableAreaID(entity);

		}

		public void DeleteByTableAreaID (System.Int64 tableAreaID)
		{
		
            tableArea.DeleteByTableAreaID(tableAreaID);

		}
		 
        public TableAreaModel GetByTableAreaID (System.Int64 tableAreaID)
        {
        
			ETableArea entity = tableArea.GetByTableAreaID(tableAreaID);
			
            TableAreaModel model = ConvertEntityToModel(entity);


            return model;
        }
        
	
		public IList<TableAreaModel> GetAll ()
		{
			IList<ETableArea> entity = tableArea.GetAll();
			
			if (entity == null)
            {
                return null;
            }
            
            IList<TableAreaModel> list = new List<TableAreaModel>();

            foreach (var item in entity)
            {
                TableAreaModel model = ConvertEntityToModel(item);
                list.Add(model);
            }
            return list;   
			
		}
		
		private TableAreaModel ConvertEntityToModel(ETableArea entity)
		{
			if (entity == null)
            {
                return null;
            }
			TableAreaModel model = new TableAreaModel();
                        model.TableAreaID = entity.TableAreaID;
                        model.Name = entity.Name;
                        model.Type = entity.Type;
                        model.Remark = entity.Remark;
                        model.CreateTime = entity.CreateTime;
                        model.UpdateTime = entity.UpdateTime;
                        return model;
		}
		
		private ETableArea ConvertModelToEntity(TableAreaModel model)
		{
			if (model == null)
            {
                return null;
            }
			ETableArea entity = new ETableArea();
                        entity.TableAreaID = model.TableAreaID;
                        entity.Name = model.Name;
                        entity.Type = model.Type;
                        entity.Remark = model.Remark;
                        entity.CreateTime = model.CreateTime;
                        entity.UpdateTime = model.UpdateTime;
                        return entity;
		}
		
		
		
		#endregion
    }
}